Ext.define('Role', {
    extend: 'Ext.data.Model',
    fields: [
         "Name"   //名称
		, "Index"   //显示顺序
		, "Flag"   //状态
        , "IsChecked"
        , "User"
    ],
    idProperty: "Id"
});

Ext.define('SHApp.Sys.Role.Grid1', {
    extend: 'BLBTSystem.grid',
    alias: 'widget.rolegrid1',
    requires: ['Ext.ux.CheckColumn'],
    //btnResetID: 'btnReset',
    autoSync: false,
    isSelModel: false,
    columns: [{
        text: "角色名称",
        flex: 1,
        dataIndex: 'Name',
        sortable: true
    }, {
        text: "操作",
        xtype: "checkcolumn",
        flex: 1,
        dataIndex: 'IsChecked',
        sortable: true
    }
    ],
    hasPageBar: false,
    userID: "",
    userName: "",
    dataModel: "Role",
    dataUrl:"api/userrole2?format=json",
    initComponent: function () {
        var me = this;
        me.btnSaveID += me.id;
        me.btnResetID += me.id;
        Ext.apply(this);
        this.creatTbar(); //
        this.callParent(arguments);
        this.checkBtnPermission(me.pvalue);
    },
    loadByUserID: function (userid, userName) {
        this.userID = userid;
        this.userName = userName;
        this.down("#" + this.btnSaveID).setDisabled(userid == "");
        this.down("#" + this.btnResetID).setDisabled(userid == "");
        var store = this.store;
        store.proxy.url = "api/userrole2?format=json&User=" + this.userID;
        store.load();

    },
    creatTbar: function () {
        var me = this;
        me.tbar = [
		            '->', {
		                xtype: 'button',
		                disabled: true,
		                id: me.btnSaveID,
		                text: '保存',
		                iconCls: 'icon-btn-save',
		                handler: function () {
		                    //var UserID = getCookie("UserID");
		                    //me.store.filters.clear();
		                    if (me.userName == "admin") {
		                        Ext.Msg.alert("提示", "您没有对该用户修改的权限！");
		                        return;
		                    }
		                    me.store.proxy.url = "api/userrole?format=json&User=" + me.userID;

		                    me.store.update();
		                    Ext.Msg.alert("提示信息", "保存成功！");
		                }
		            }, ' ', {
		                xtype: 'button',
		                disabled: true,
		                id: me.btnResetID,
		                text: '重置',
		                iconCls: 'icon-btn-reset',
		                handler: function () {
		                    me.store.reLoad();
		                }
		            }
        ]
    }

})

